<%@page import="java.util.Date"%>
<%@page import="com.web.entity.Teacher"%>
<%@page errorPage="TloginerrorPage.jsp" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Teacher Message</title>
    <body>
        <div id="navdiv">
            <div class="top_navdiv">
                <div class="top_left">教师中心</div>
                <div class="identity">
                    <span>您好</span>
                    <div class="user_li">
                        <canvas id="myCanvas" width="100" height="30">
                        </canvas>
                    </div>
                </div>
            </div>
        </div>
        <div class="navbar  control_nav" >
            <div class="container"  style="margin-left: 300px; ">
                <ul class="nav navbar-nav navul">
                    <li class="col-md-2">
                        <a href="teacherApplyTest.jsp">申请/取消考试</a>
                    </li>
                    <li class="col-md-2">
                        <input type="hidden" name="ClassID" class="form-control" >
                        <a href="ssls">查看班级列表</a>
                    </li>
                    <li class="col-md-2">
                        <a href="SearchOneStudent.html">查询单个学生</a>
                    </li>
                    <li class="col-md-2">
                        <a href="sosgs">查询学生成绩</a>
                    </li>
                    <li class="col-md-2">
                        <a href="scgs">查询班级成绩</a>
                    </li>

                </ul>
            </div>
        </div>
        <link rel="stylesheet" href="css/bootstrap.min.css"/>
        <link rel="stylesheet" href="css/newcss1.css">
        <link rel="stylesheet" href="css/mycss_foradim.css"/>
        <script src="js/jquery-3.4.1.min.js"></script>
        <script src="js/bootstrap.min.js"></script>
        <script src="js/script.js" charset="UTF-8"></script> 
        <script type="text/javascript" src="js/circle.js" charset="UTF-8"></script>
        
        <hr>
        
        
        <%
            Teacher t = (Teacher) session.getAttribute("tea");
        %>
        
<div class="container">
    <div class="col-md-3 main_div nav_list">
                <span><b>教师</b></span>
                <div class="div_line"></div>
                <ul>
                    <li>
                        <img class="img-circle" width="74px" height="70px;" src="img/login_img.jpg" alt="图片加载失败">
                    </li>
                        <span class="glyphicon glyphicon-chevron-right"></span><a href="teacherlogin.html"><span>返回登录页面</span></a>
                </ul>
    </div>
    <div class="col-md-1"></div>
    <div class="col-md-8 main_div">
        <table id="dataTable" class="table-condensed table-hover test_table table-striped">
            <tr class="table-hover">
                <th class="text-center">教师编号</th>
                <th class="text-center">教师姓名</th>
                <th class="text-center">帐号状态</th>
                <th class="text-center">教授课程号</th>
                <th class="text-center">教授班级号</th>
                <th class="text-center">操作</th>
            </tr>

            <tr class="forEach_tr" id="tr<%=t.getTid() %>">
                <td class="col-md-2 text-center"><%=t.getTid()%></td>
                <td class="col-md-2 text-center"><%=t.getTname()%></td>
                <td class="col-md-2 text-center"><%=t.getTstatus()%></td>
                <td class="col-md-2 text-center"><%=t.getCourseID()%></td>
                <td class="col-md-2 text-center"><%=t.getClassID()%></td>
                <td class="text-center"> <a href="javascript:showModifyModal('#tr<%=t.getTid()%>');" class="text-success">编辑</a><br>
                    <a href="javascript:showModifyTpwdModal('#tr<%=t.getTid()%>');" class="text-danger">修改密码</a>
                </td>
            </tr>
        </table>
    </div>
<!--编辑教师信息框-->
</div>
        <div class="modal fade" id="modify_modal" tabindex="-1">
            <div class="modal-dialog">
                <div class="bg-warn modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title text-primary" id="myModalLabel">编辑教师信息</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-inline" id="modify_form">
                            <label for="tid">教师编号：</label>
                            <input id="tid" type="text" name="Tid" readonly class="form-control">
                            <br><br>
                            <label for="iname">教师姓名：</label>
                            <input id="iname" type="text" name="Tname" class="form-control">
                            <br><br>
                            <label for="istatus">账号状态：</label>
                            <select id="istatus" name="Tstatus" class="form-control">
                                <option value="1">1</option>
                            </select>
                            <br><br>
                            <label for="icourse">教授课程号：</label>
                            <select id="icourse" name="CourseID" class="form-control">
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                                <option value="6">6</option>
                                <option value="7">7</option>
                            </select>
                            <br><br>
                            <label for="iclass">教授班级号：</label>
                            <select id="iclass" name="ClassID" class="form-control">
                                <option value="2018001">2018001</option>
                                <option value="2018002">2018002</option>
                                <option value="2018003">2018003</option>
                                <option value="2018004">2018004</option>
                            </select>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-info" data-dismiss="modal">取消</button>
                        <button type="button" id="btn_modify" class="btn btn-primary">保存修改</button>
                    </div>
                </div>
            </div>
        </div>

<!--修改教师密码-->
        <div class="modal fade" id="modifytpwd_modal" tabindex="-1">
            <div class="modal-dialog">
                <div class="bg-warn modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title text-primary" id="myModalLabel">修改教师密码</h4>
                    </div>
            <div class="modal-body">
                <form class="form-inline" id="modifypwd_form" action="action" class="container">
                    <label for="tid">教 &nbsp;师  &nbsp;编  &nbsp;号&nbsp;:&nbsp;&nbsp;&nbsp;</label>
                    <input id="tid" type="text" name="Tid" readonly class="form-control">
                    <br><br>
                    <label for="tpwd1">请输入原密码：</label>
                    <input id="tpwd1" type="text" name="NTpwd" class="form-control">
                    <br><br>
                    <label for="tpwd">请输入新密码：</label>
                    <input id="tpwd" type="text" name="Tpwd" class="form-control">
                    <br><br>
                    <label for="ntpwd1">请确认新密码：</label>
                    <input id="ntpwd1" type="text" name="NTpwd1" class="form-control">
                    <br><br>
                    <input type="hidden" name="tid" id="tid" value="{$Tid}">
                </form>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-info" data-dismiss="modal">取消</button>
                <button type="button" id="btn_modifyTpwd" class="btn btn-primary">保存密码</button>
            </div>
        </div>
      </div>
    </div>
            <script>
    $(document).ready(function(){
    
    //点击"保存密码"按钮，发送请求给mtps这个Servlet，修改数据库中对应的信息
    $("#btn_modifyTpwd").click(function(){
        $.ajax({
            url:"mtps",
            type:"POST",
            data: $("#modifypwd_form").serialize(),
            success:function(rows){
                if(rows!=1){
                    alert("修改失败！");
                    return;
                }else
                if($('#tpwd1').val()==""){
		alert('原始密码为空！');
		return;
	        }else
                
                if($('#tpwd1').val()!=<%=t.getTpwd()%>){
                    alert('原密码输入错误！');
                }else

	        if($('#tpwd').val()==""){
		alert('新密码为空！');
		return;
	        }else
                
	        if($('#ntpwd1').val()==""){
		alert('确认密码为空！');
		return;
	        }else
                
                if($('#ntpwd1').val()!=$('#tpwd').val()){
		alert('两次输入密码不一致！');
		return;
	        }else
               
                if($('#tpwd').val()==$('#tpwd1').val()){
		alert('新密码不能与原密码相同！');
		return;
	        }else
                
                if($('#ntpwd1').val()==$('#tpwd1').val()){
		alert('新密码不能与原密码相同！');
		return;
                }else
                {
                var rowId = "#tr"+$("#modifypwd_form #tid").val();
                $(rowId+" td:eq(6)").text($("#modifypwd_form #tpwd").val());
                $("#modifytpwd_modal").modal("hide");
                alert('您已修改密码，请重新登录！');
                window.location.href ='teacherlogin.html';
                }
            },
            error:function(){
                alert("请求处理出错，修改失败！");
            }
        });
    });
});
            </script>              
    </body>
</html>
